package com.hellpro.lolbox.mine.presenter;

import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.hellpro.lolbox.mine.view.ILoginSttingActivity;

/**
 * 类描述:
 * 创建人:阿犇
 * 创建时间:2016/10/25
 * 备注:
 */

public class LoginSettingPresenter {

    private ILoginSttingActivity mILoginSettingActivity;
    private PopupWindow popupWindow;

    public LoginSettingPresenter(ILoginSttingActivity iLoginSttingActivity){
        this.mILoginSettingActivity = iLoginSttingActivity;
    }


    /**
     *
     * 类描述:
     * 创建人:阿犇
     * 创建时间:2016/10/25
     * 备注:处理退出登录
     *
     */
    public void setUnLogin(){
        final LinearLayout view = mILoginSettingActivity.getPopupWindow();

        if (popupWindow == null) {

            popupWindow = new PopupWindow(mILoginSettingActivity.getLoginSettingContext());
            popupWindow.setBackgroundDrawable(new BitmapDrawable());

            popupWindow.setFocusable(true); // 设置PopupWindow可获得焦点
            popupWindow.setTouchable(true); // 设置PopupWindow可触摸
            popupWindow.setOutsideTouchable(true); // 设置非PopupWindow区域可触摸
            popupWindow.setContentView(view);
            ColorDrawable dw = new ColorDrawable(Color.parseColor("#aaaaaa"));
            //设置SelectPicPopupWindow弹出窗体的背景
            popupWindow.setBackgroundDrawable(dw);
            popupWindow.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
            popupWindow.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
//            popupWindow.setAnimationStyle(R.style.popuStyle);   //设置 popupWindow 动画样式
        }
        popupWindow.showAtLocation(mILoginSettingActivity.getBtnUnLogin(), Gravity.CENTER, 0, 0);
        popupWindow.update();


    }
    /**
     *
     * 类描述:
     * 创建人:阿犇
     * 创建时间:2016/10/25
     * 备注:设置popup点击
     */

    public void setBack(){
        SharedPreferences sp = mILoginSettingActivity.getSP();
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putBoolean("isLogin", false);
        editor.commit();
        popupWindow.dismiss();
        mILoginSettingActivity.getBtnUnLogin().setVisibility(View.GONE);
    }
}

